using System;
using System.Diagnostics;
using System.Collections.Generic;
using org.tmatesoft.svn.core;
using org.tmatesoft.svn.core.wc;

namespace Subsync.Core.Subversion
{
	/// <summary>
	/// Author: Zhang Andy
	/// </summary>
    class SVNUnlock : CommandBase
    {
        // Initialise variables with default settings.
        private int no_of_filepath;
        private java.io.File[] file_path; //url of file to be locked
        private bool breakLock = true; //other users may take over the lock

        // Minimal constructor.
        public SVNUnlock(string filePath)
        {
            Debug.WriteLine("SVN Unlock minimal Constructor with defaults");
            List<string> path = new List<string>();
            path.Add(filePath);
            this.no_of_filepath = path.Count;
            this.file_path = new java.io.File[no_of_filepath];
            for (int i = 0; i < no_of_filepath; i++)
                file_path[i] = new java.io.File(path[i]);
        }

        // Full constructor
        public SVNUnlock(List<string> path, bool breakLock)
        {
            Debug.WriteLine("SVN Unlock full Constructor with defaults");

            this.breakLock = breakLock;
            this.no_of_filepath = path.Count;
            this.file_path = new java.io.File[no_of_filepath];
            for (int i = 0; i < no_of_filepath; i++)
                file_path[i] = new java.io.File(path[i]);
        }

        public override void Execute()
        {
            Debug.WriteLine("SVN Unlock Execution");

            //library setup
            Tools.SetupLibrary();

            //load up the clients
            SVNClientManager cm = SVNClientManager.newInstance();

            try
            {
                cm.getWCClient().doUnlock(this.file_path, this.breakLock);
            }
            catch (SVNException e)
            {
                throw new SVNExecuteException(e.getMessage());
            }
        }
    }
}
